/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package threads;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BoxLayout;

/**
 *
 * @author Jakim
 */
public class LabelThreads extends Frame {

    Panel panelWithLabels;
    Panel panelButton;
    Button btnClickMe;
    int i = 1;

    public LabelThreads(){
        this.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
        this.btnClickMe = new Button("ClickMe");
        this.panelWithLabels = new Panel();
        this.panelButton = new Panel();
        this.btnClickMe.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                Label lbl = new Label("Starting");
                Thread t = new Thread(new MyThread("Thread " + i++, lbl));
                panelWithLabels.add(lbl);
                t.start();
                panelWithLabels.setSize(new Dimension(500, 500));
            }
        });
        this.panelWithLabels.setLayout(new BoxLayout(this.panelWithLabels, BoxLayout.Y_AXIS));
        this.panelWithLabels.setPreferredSize(new Dimension(500, 500));
        this.panelButton.add(this.btnClickMe);
        this.add(this.panelButton);
        this.add(this.panelWithLabels);
        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                System.exit(0);
            }

        });
        this.pack();
        this.setVisible(true);
    }

    public static void main(String[] args){
        new LabelThreads();
    }

}
